home *** CD-ROM | disk | FTP | other *** search
/ STraTOS 1997 April & May / STraTOS 1 - 1997 April & May.iso / CD01 / INTERNET / SITES / GRAHAM / XA_6S.ZIP / SOURCE / APP_MAN.C < prev    next >
Encoding:
C/C++ Source or Header  |  1996-05-05  |  5.8 KB  |  220 lines

  1. /*
  2.  * XaAES - XaAES Ain't the AES
  3.  *
  4.  * A multitasking AES replacement for MiNT
  5.  *
  6.  */
  7.  
  8. #include <OSBIND.H>
  9. #include <FILESYS.H>
  10. #include <MINTBIND.H>
  11. #include <SIGNAL.H>
  12. #include "XA_DEFS.H"
  13. #include "XA_TYPES.H"
  14. #include "XA_GLOBL.H"
  15. #include "K_DEFS.H"
  16. #include "XA_CODES.H"
  17. #include "NEW_CLNT.H"
  18. #include "C_WINDOW.H"
  19. #include "DESKTOP.H"
  20. #include "SYSTEM.H"
  21. #include "RESOURCE.H"
  22. #include "STD_WIDG.H"
  23.  
  24. /*
  25.     Application Manager
  26.     This module handles various ways of swapping the current application...
  27. */
  28.  
  29. short dead_exit_contrl[]={XA_CLIENT_EXIT,0,0,0,0};
  30. AESPB dead_client_pb;
  31.  
  32. /*
  33.     Go round and check whether any clients have died & we didn't notice.
  34.     - Useful for cleaning up clients that weren't launched via a shell_write.
  35. */
  36. void find_dead_clients(void)
  37. {
  38.     short app;
  39.     long r;
  40.     K_CMD_PACKET dead_client_packet;
  41.     XA_CLIENT *client;
  42.     
  43.     for(app=0; app<MAX_PID; app++)
  44.     {
  45.         client=Pid2Client(app);
  46.         if (client)
  47.         {
  48.             if ((app!=AESpid)&&(client->clnt_pipe_rd))        /* Is this a valid application? */
  49.             {
  50.                 r=Pkill(app,SIGNULL);    /* poll to see if the client has died since we last looked.... */
  51.     
  52.                 if (r)
  53.                 {
  54.                     Pwait3(1,NULL);
  55.  
  56.                     DIAGS(("Dead client [%s:pid=%d] - cleaning up\n",clients[app].name,app));
  57.                 
  58.                     dead_client_pb.contrl=dead_exit_contrl;    /* If client is dead, send ourselves a message to clean up.... */
  59.                     dead_client_packet.pid=app;                /* client pid */
  60.                     dead_client_packet.cmd=AESCMD_NOREPLY;    /* no reply */
  61.                     dead_client_packet.pb=&dead_client_pb;    /* pointer to AES parameter block */
  62.  
  63.                     XA_client_exit(app,&dead_client_pb);    /* Run the application exit cleanup */
  64.                 
  65.                     Fclose(client->clnt_pipe_wr);            /* Close the kernal end of client reply pipe */
  66.                     client_handle_mask&=~(1L<<client->clnt_pipe_wr);
  67.                 
  68.                     client->clnt_pipe_wr=client->clnt_pipe_rd=0; 
  69.                 }
  70.             }
  71.         }
  72.     }
  73. }
  74.  
  75. /*
  76.     Attempt to recover a system that has locked up
  77. */
  78. void recover(void)
  79. {
  80.     K_CMD_PACKET dead_client_packet;
  81.     long r;
  82.     
  83.     DIAGS(("Attempting to recover control.....\n"));
  84.  
  85.     if ((update_lock)&&(update_lock!=AESpid))
  86.     {
  87.         DIAGS(("Killing owner of update lock\n"));
  88.         r=Pkill(update_lock,SIGKILL);
  89.     }
  90.     
  91.     if (((mouse_lock)&&(mouse_lock!=update_lock))&&(mouse_lock!=AESpid))
  92.     {
  93.         DIAGS(("Killing owner of mouse lock\n"));
  94.         r=Pkill(mouse_lock,SIGKILL);
  95.     }
  96.     
  97.     v_show_c(V_handle, 0);
  98. }
  99.  
  100. /*
  101.     Swap the main root window's menu-bar to be the next application's
  102.     (cycle's which app own's the main menu-bar).
  103.     NOTE: This only swap's the menu-bar, it doesn't swap the topped window.
  104. */
  105. void next_app_menu(void)
  106. {
  107.     XA_WIDGET_TREE *menu_bar=(XA_WIDGET_TREE*)(root_window->widgets[XAW_MENU].stuff);
  108.     short next_app,start_app;
  109.     
  110.     start_app=menu_bar->owner;
  111.     
  112.     next_app=start_app+1;
  113.     
  114.     do {
  115.         if (next_app>=MAX_PID)
  116.             next_app=0;
  117.             
  118.         if ((clients[next_app].clnt_pipe_rd)||(next_app==AESpid))    /* Valid client ? */
  119.         {
  120.             if (clients[next_app].std_menu!=menu_bar->tree)    /* Different menu? */
  121.             {
  122.                 GRECT clip;
  123.         
  124.                 menu_bar->tree=clients[next_app].std_menu;
  125.                 
  126.                 if (clients[next_app].std_menu==clients[AESpid].std_menu)
  127.                     menu_bar->owner=AESpid;        /* Apps with no menu get the default menu, and that's owned by the AES */
  128.                 else
  129.                     menu_bar->owner=next_app;    /* Apps with menu's own their own menu */
  130.             
  131.                 rp_2_ap(root_window, root_window->widgets+XAW_MENU, &clip.g_x, &clip.g_y);
  132.  
  133.                 clip.g_w=root_window->widgets[XAW_MENU].w;
  134.                 clip.g_h=root_window->widgets[XAW_MENU].h;
  135.  
  136.                 v_hide_c(V_handle);
  137.                 display_non_topped_window(root_window,&clip);
  138.                 v_show_c(V_handle,1);
  139.             }else{                                            /* Same menu, just a different owner... */
  140.                 menu_bar->owner=next_app;
  141.             }
  142.             
  143.             if ((clients[next_app].desktop)                    /* Change desktops? */
  144.                 &&((clients[next_app].desktop!=desktop)&&(clients[next_app].desktop!=ResourceTree(system_resources,DEF_DESKTOP))))
  145.             {
  146.                 set_desktop(clients[next_app].desktop);
  147.                 root_window->owner=next_app;
  148.  
  149.                 v_hide_c(V_handle);
  150.                 display_non_topped_window(root_window,NULL);
  151.                 v_show_c(V_handle,1);
  152.             }
  153.             
  154.             return;
  155.         }
  156.         next_app++;
  157.     } while (next_app!=start_app);
  158.  
  159. }
  160.  
  161. void list_apps(void)
  162. {
  163.     short f;
  164.     
  165.     DIAGS(("========== XaAES Client Applications List ===========\n"));
  166.     
  167.     for(f=0; f<MAX_PID; f++)
  168.     {
  169.         if (clients[f].clnt_pipe_rd)
  170.         {
  171.             DIAGS(("%d:%s..Wait[",f,clients[f].name));
  172.             if (clients[f].waiting_for&XAWAIT_BUTTON)
  173.                 DIAGS(("B"));
  174.             if (clients[f].waiting_for&XAWAIT_KEY)
  175.                 DIAGS(("K"));
  176.             if (clients[f].waiting_for&XAWAIT_MOUSE1)
  177.                 DIAGS(("1"));
  178.             if (clients[f].waiting_for&XAWAIT_MOUSE2)
  179.                 DIAGS(("2"));
  180.             if (clients[f].waiting_for&XAWAIT_MESSAGE)
  181.                 DIAGS(("M"));
  182.             if (clients[f].waiting_for&XAWAIT_TIMER)
  183.                 DIAGS(("T"));
  184.             if (clients[f].waiting_for&XAWAIT_CHILD)
  185.                 DIAGS(("C"));
  186.             if (clients[f].waiting_for&XAWAIT_MULTI)
  187.                 DIAGS(("{MULTI}"));
  188.             DIAGS(("]:AESparent=%d",clients[f].parent));
  189.             if (clients[f].std_menu)
  190.                 DIAGS((":HasMenubar"));
  191.             if (((XA_WIDGET_TREE*)root_window->widgets[XAW_MENU].stuff)->owner==f)
  192.                 DIAGS(("(current)"));
  193.             if (clients[f].desktop)
  194.                 DIAGS((":OwnsDesktop"));
  195.             if (clients[f].msg)
  196.                 DIAGS((":MsgPending"));
  197.             if (mouse_lock==f)
  198.                 DIAGS((":OwnsMouseLock"));
  199.             if (update_lock==f)
  200.                 DIAGS((":OwnsUpdateLock"));
  201.             
  202.             DIAGS(("\n"));
  203.         }
  204.     }
  205. }
  206.  
  207. void status_dump(void)
  208. {
  209.     DIAGS(("========== XaAES Status ===========\n"));
  210.  
  211.     DIAGS(("AESpid=%d\n",AESpid));
  212.     
  213.     DIAGS(("Display Device: P_handle=%d, V_handle=%d\n",P_handle,V_handle));
  214.     DIAGS((" size=[%d,%d], colours=%d, bitplanes=%d\n",display.w,display.h,display.colours,display.planes));
  215.  
  216.     DIAGS(("mouse_lock=%d, mouse_cnt=%d\n",mouse_lock,mouse_cnt));
  217.     DIAGS(("updae_lock=%d, update_cnt=%d\n",update_lock,update_cnt));
  218.     
  219.     DIAGS(("root window menu : owner=%d\n",((XA_WIDGET_TREE*)root_window->widgets[XAW_MENU].stuff)->owner));
  220. }